package Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import Entity.*;
import Util.JdbcUtil;

public class AddRefundProveDao {
    //存入预付款存入凭证
    public void add(RefundProveEntity refund) {
        try {
            Connection conn = JdbcUtil.getConnection();
            //insert into pay(num,name,time,total,surplus,operator) values('61021','张根群','2015-09-08 09:51','50000','1000','郑斌');
            String sql = "insert into refund(num,name,code,time,order_in,refund_total,surplus,operator,project,nullify) values('" + refund.getNum() + "','" + refund.getName() + "','" + refund.getCode() + "','" + refund.getTime() + "','" + refund.getOrder_in() + "','" + refund.getRefund_total() + "','" + refund.getSurplus() + "','" + refund.getOperator() + "','" + refund.getProject() + "',0);";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.executeUpdate();
            JdbcUtil.close(pstmt, conn);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    //获得num的值
    public int select_num() {
        int num = 0;
        String sql = "select MAX(num) FROM refund;";
        try {
            Connection conn = JdbcUtil.getConnection();
            PreparedStatement pstmt = conn.prepareStatement(sql);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                num = rs.getInt(1);
            }
            JdbcUtil.close(pstmt, conn);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return num;
    }
}

